package com.zthz.douxing.utils

import com.zthz.douxing.command.DouXingCommand
import grails.plugin.gson.converters.GSON
import org.apache.commons.logging.Log

/**
 * @desc 设置返回信息的工具类
 * @author zsw
 * @date Mar 20, 2014
 */
class MessageUtils {

    def errorMessageServicesService

    static def messageSource


    /**
     * @desc 添加错误日志并且返回错误信息
     * @param CommandAndLog 类
     * @return 错误信息的JSON串
     * @author zsw
     * @date Mar 20, 2014
     */
    static getCommandErrorMsgAsJSON(CommandAndLog cl){
        cl.log.debug("${cl.errorMsg} ")
        ["status": 1, "errMsg": cl.errorMsg, "data": []] as GSON
    }

    static  getCommandErrorMsgAsJSON(String errorMsg){

        ["status": 1, "errMsg":errorMsg,"data": []] as GSON
    }
    static  getErrorMsgAsJSON(String errorMsg){

        ["status": 1, "errMsg":errorMsg,"data": []] as GSON
    }

    /**
     *
     * @return json
     * @desc 获取非AJAX错误提示请求的json对象
     * @author zsw
     * @date Mar 20, 2014
     */
    static getIsNotAJAXMsgAsJSON(errorDesc){

        ["status": 1, errMsg: errorDesc, "data": []] as GSON
    }
    /**
     *
     * @return json
     * @desc 获取请求成功的json对象(成功后无返回数据)
     * @author zsw
     * @date Mar 20, 2014
     */
    static getSuccessfullMsgAsJSON(){

        ["status": 0, errMsg: "", "data": []] as GSON;
    }
    /**
     *
     * @return json
     * @desc 获取请求成功的json对象 (成功后带有返回数据的)
     * @author zsw
     * @date Mar 20, 2014
     */
    static getSuccessfullMsgAsJSON(map){
        ["status": 0, errMsg: "", "data":map] as GSON;

    }
/**
 *
 * @return json
 * @desc 获取请求成功的string对象 (成功后带有返回数据的)
 * @author zsw
 * @date Mar 20, 2014
 */
    static getSuccessfullMsgAsStr(String str){
        ["status": 0, errMsg: "", "data":str] as GSON

    }

    static getSuccessfullMsgAsStNoJSON(String str){

        "{'status': 0, 'errMsg': '', 'data':"+str+"}"
    }

}
/**
 * @desc MessageUtils 的 方法传递参数类 
 * 		 Command 错误的命令对象 
 * 		 Log 添加错误日志的对象 
 * @author zswsecurityConfig
 * @date Mar 20, 2014
 */
class CommandAndLog{
    def command;
    String errorMsg;
    Log log;
}
